/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

export function fooStr() {
  return "OK";
}

export function fooNum1(num) {
  return num;
}

export function fooNum2(num1, num2) {
  return num2;
}

export function fooDefault1(num = 11) {
  return num;
}

export function fooDefault2(num1 = 11, num2 = 12) {
  return num2;
}

export const fooLam = () => 100;

export const fooLamDefault = (num = 123) => num;

export function fooDefaultMix(num = 21, str = "OK") {
  return string(num) + str;
}

export function fooDefaultNum(str = "OK") {
  return str;
}

export function fooDefaultThree(num = 21, str1 = ",str1Default", str2 = ",str2Default") {
  return string(num) + str1 + str2;
}

export const globalBoolean = false

export function fooVoid(globalBoolean) {
  globalBoolean = true;
}

export function arguments0() {
  return "Arguments = 0";
}

export function arguments3(num1, num2, num3) {
  return num1 + num2 + num3;
}

export function argumentsMix3(num, str, boo) {
  return string(num) + str + string(boo);
}

export function argumentsMix4(num, boo1, str, boo2,) {
  return string(num) + string(boo1) + str + string(boo2);
}

export function restStr(...str) {
  let result = "";
  for (let i = 0; i < str.length; i++) {
    result += string(str[i]);
  }
  return result;
}

export function restMixStr(callback, ...str2) {
  let result = "";
  result += callback(...str2)
  return result;
}

export function restMix(callback, ...str2) {
  let result = "";
  result += callback(...str2);
  return result;
}

let handler = null;

export function initHandler(foo) {

  function my_handler() {
    console.log("in my_handler");
    console.log(foo.bar);
  }

  handler = my_handler;
  return "OK"
}

export function getHandler() {
  if (handler == null) {
    throw new Error("Handler is not set");
  }
  return "OK";
}